import java.util.ArrayList;
import java.util.Random;


public class Field {
	Tower[] towers;
	int[][] distances;
	int playerCount;
	
	ArrayList<Soldier> soldiers = new ArrayList<Soldier>();
	public Field(int seed, int towerCounts, int width, int height, int playerCount) {
		Random r = new Random(seed);
		towers = new Tower[towerCounts];
		this.playerCount = playerCount;
		
		int[] xplayers = {0, width / 2, width / 2, width};
		int[] yplayers = {height / 2, 0, height, height / 2};
		for (int i = 0; i < playerCount; i++){
			towers[i] = new Tower(playerCount, i, 0, xplayers[i], yplayers[i], distances[i]);
		}
		for (int i = playerCount; i < towers.length; i++) {
			int curx = r.nextInt(height);
			int cury = r.nextInt(width);
			
			//@warning here is some bad code. You may fix it, if you want
			boolean placeIsUsed = false;
			
			
			for (int j = 0; j < i; j++) {
				if (towers[j].x == curx && towers[j].y == cury){
					placeIsUsed = true;
				}
			}
			
			if (placeIsUsed){
				i--;
				continue;
			}
			towers[i].x = curx;
			towers[i].y = cury;
		}
		for (int i = 0; i < towers.length; i++) {
			for (int j = 0; j < towers.length; j++) {
				int dx = towers[i].x - towers[j].x;
				int dy = towers[i].y - towers[j].y;
				distances[i][j] = (int) Math.sqrt(dx * dx + dy * dy);
			}
		}
	}
	
}
